package com.study.flyweight.general;

/**
 * 享元模式
 * 大量细粒度对象的重复使用
 * String、Integer等常量池，数据库连接池、缓存池
 * 内部状态：指对象共享出来的信息，存储在共享对象内部并且不会随环境的改变而改变(棋子的颜色)
 * 外部状态：对象依赖的标记，随环境改变而改变，不可共享的状态(棋子的位置)
 */
public class Client {
    public static void main(String[] args) {
        int extrinsic = 22;

        Flyweight flyweightX = FlyweightFactory.getFlyweight("X");
        flyweightX.operate(extrinsic++);

        Flyweight flyweightY = FlyweightFactory.getFlyweight("Y");
        flyweightY.operate(extrinsic++);

        Flyweight flyweightZ = FlyweightFactory.getFlyweight("Z");
        flyweightZ.operate(extrinsic++);

        Flyweight flyweightReX = FlyweightFactory.getFlyweight("X");
        flyweightReX.operate(extrinsic++);

        Flyweight unsharedFlyweight = new UnsharedConcreteFlyweight("X");
        unsharedFlyweight.operate(extrinsic++);
    }
}
